package com.atguigu.exer1;

public class TestGraphics {
    public static void main(String[] args) {
        Graphic[] shapes = new Graphic[3];
        shapes[0] = new Circle(2.5);
        shapes[1] = new Rectangle(5,1);
        shapes[2] = new Triangle(3,4,5);
        System.out.println("排序前：");
        for (int i = 0; i < shapes.length; i++) {
            System.out.println(shapes[i]);
        }

        //按照面积排序
        for (int i = 1; i < shapes.length; i++) {
            for (int j = 0; j < shapes.length - i; j++) {
                if(shapes[j].area() > shapes[j+1].area()){
                    Graphic temp = shapes[j];
                    shapes[j] = shapes[j+1];
                    shapes[j+1] = temp;
                }
            }
        }

        System.out.println("排序后：");
        for (int i = 0; i < shapes.length; i++) {
            System.out.println(shapes[i]);
        }
    }
}